package cn.jdy.plugins.web;

import cn.jdy.common.constant.GlobalConstant;
import cn.jdy.common.ctrl.BaseCtrl;
import cn.jdy.framework.log.BaseLog;
import cn.jdy.platform.entity.ConfValue;
import cn.jdy.platform.service.ConfService;
import cn.jdy.plugins.entity.HelpInfo;
import cn.jdy.plugins.service.HelpService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @title 帮助信息控制类
 * @date 2014-03-12
 */
@Controller
@RequestMapping("/help")
public class HelpCtrl extends BaseCtrl {

	@Autowired
	private HelpService helpService;
	@Autowired
	private ConfService confService;

	/**
	 * 帮助中心详细内容页
	 * @param id
	 * @return
	 */
	@RequestMapping("/show-{id}.html")
	public ModelAndView queryDetail(@PathVariable Integer id) {
		ModelAndView mv = new ModelAndView("/help/helpDetail.jsp");
		Map<ConfValue, List<HelpInfo>> map = new LinkedHashMap<ConfValue, List<HelpInfo>>();
		try {
			List<ConfValue> plist = confService.queryByType(GlobalConstant.TYPE_HELP, 0L);// 帮助中心;
			for(ConfValue bo : plist){
        HelpInfo helpInfo = new HelpInfo();
        helpInfo.setColumnid(String.valueOf(bo.getId()));
        map.put(bo, helpService.findbytype(helpInfo,false));
      }
			HelpInfo help = helpService.findOne("id",id,"status","1");
			help.setColumnname(confService.find(Long.valueOf(help.getColumnid())).getValue0());
			mv.addObject("help", help);
			mv.addObject("helpClass", map);
		} catch(Exception e) {
			BaseLog.e(this.getClass(), "查询帮助中心详细内容异常", e);
		}
		return mv;
	}
	
	/**
	 * 帮助中心-我要留言
	 * @param id
	 * @return
	 */
	@RequestMapping("/helpGusebook")
	public ModelAndView helpGusebook() {
	  ModelAndView mv = new ModelAndView("/help/helpGusebook.jsp");
	  Map<ConfValue, List<HelpInfo>> map = new LinkedHashMap<ConfValue, List<HelpInfo>>();
		try {
			List<ConfValue> plist = confService.queryByType(GlobalConstant.TYPE_HELP, 0L);// 帮助中心;
			for(ConfValue bo : plist){
		      HelpInfo helpInfo = new HelpInfo();
		      helpInfo.setColumnid(String.valueOf(bo.getId()));
		      map.put(bo, helpService.findbytype(helpInfo,false));
		    }
			mv.addObject("helpClass", map);
		} catch(Exception e) {
			BaseLog.e(this.getClass(), "帮助中心-我要留言异常", e);
		}
	  return mv;
	}
}
